var iconimg = '';
var token = localStorage.getItem('tok');
//获取个人信息
$.ajax({
    type: "GET",
    url: $host+'/api/app/person/perUserInfo',
    async: true,
    dataType:'json',
    data: {
        token:token
    },
    success: function(result){
        var data=result.data;
        $('.name').text(data.name);
        $('.userId').text(data.userId);
        $('.cardNum').text(data.cardNum);
        $('.phone').val(data.phone);
        $('.email').val(data.email);
        $('.qqNum').val(data.qqNum);
    },
    error:function(){
        console.log('接口错误')
    }
});
$.ajax({
    type: "GET",
    url: $host+'/api/app/person/userInfo',
    async: true,
    dataType:'json',
    data: {
        'token':token
    },
    success: function(result){
        var data=result.data.icon;
        if(data){
            $('.iconimg-b').css('background','url('+data+')no-repeat center/100% 100%');
            $('.iconimg').css('background','url('+data+')no-repeat center/100% 100%');
            $('.iconimg').css('background-size','cover');
        }else {
            $('.information_icon').css('background',`url('../images/porfile_profile photo@2x.png')`);
            $('.information_icon').css('background-size','cover');
        }
    },
    error:function(){
        console.log('接口错误')
    }
});
//点击保存
$('.btn').click(function(){
    $.ajax({
        type: "POST",
        url: $host+'/api/app/person/perUserInfoUpdate1',
        async: true,
        dataType:'json',
        data: {
            'token':token
        },
        data:{
            "email":$('.email').val(),
            "qqNum":$('.qqNum').val(),
            'token':$.cookie('token')
        },
        success: function(result){
            console.log(result)
        },
        error:function(){
            console.log('接口错误')
        }
    });
    $.ajax({
        type: "POST",
        url: $host+'/api/app/person/changeIcon',
        async: true,
        dataType:'json',
        data: {
            'token':token,
            'icon': iconimg
        },
        success: function(result){
            console.log(result);
        },
        error:function(){
            console.log('接口错误')
        }
    });
})
//更换头像
$('.portrait-white-b').bind('click',function () {
    $('.upImg_max').trigger('click');
});
$('.upImg_max').on('change',function () {
    $.ajax({
        url:$host+ "/api/upload/imgsIc",
        type: 'POST',
        cache: false,
        data: new FormData($('.infoLogoForm_max')[0]),
        processData: false,
        contentType: false,
        dataType:"json",
        beforeSend: function(){
        },
        success : function(res) {
            if(res.data.address){
                let {data:{address}} = res;
                iconimg = address;
                $('.iconimg-b').css('background','url('+iconimg+')no-repeat center/100% 100%');
                $('.iconimg').css('background','url('+iconimg+')no-repeat center/100% 100%');
                $('.iconimg').css('background-size','cover');
            }
        },
        error:()=>{
            console.log('接口错误');
        }
    });
});
//点击返回
$('.grxxfh').click(function(){
    window.location.href="gerenzx.html?token="+token;
})

